package com.mofofa.maozy.repay.naira

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.mofofa.maozy.base.BaseViewModel
import com.mofofa.maozy.data.*
import com.mofofa.maozy.network.ApiUserReposity

class PaystackNgnViewModel : BaseViewModel() {

    /** 默认卡列表 */
    var mMaozyDefMaozyBankMaozyAccountMaozyList = mutableListOf<RevObjPaystackCardListNgn>()

    /** 还款金额 */
    var mMaozyRepayMaozyAmount: String = ""

    /** 卡号 */
    var mMaozyCardMaozyNum: String = ""

    /** 有效年 */
    var mMaozyEMaozyYear: String = ""

    /** 有效月 */
    var mMaozyEMaozyMonth: String = ""

    /** 有效cvv */
    var mMaozyEMaozyCvv: String = ""

    /** 线下账号名称 */
    var mMaozyVirtualMaozyBankMaozyName: String = ""

    /** 线下账号号码 */
    var mMaozyVirtualMaozyBankMaozyAccount: String = ""

    /** 获取虚拟账号信息监听 */
    private val mMaozyFetchMaozyVirtualMaozyAccountMaozyLiveData = MutableLiveData<ReqBase>()

    /** 初始化paystack监听 */
    private val mMaozyInitMaozyPaystackMaozySdkMaozyLiveData = MutableLiveData<ReqPaystackOrderInitNgn>()

    /** 获取paystack卡列表监听 */
    private val mMaozyFetchMaozyPaystackMaozyCardMaozyListMaozyLiveData = MutableLiveData<ReqBase>()

    /** 获取虚拟账号信息监听 */
    val onMaozyFetchMaozyVirtualMaozyAccountMaozyLiveData =
        Transformations.switchMap(mMaozyFetchMaozyVirtualMaozyAccountMaozyLiveData) { query ->
            ApiUserReposity.fetchMaozyVirtualMaozyAccount(this, query)
        }

    /** 初始化paystack监听 */
    val onMaozyInitMaozyPaystackMaozySdkMaozyLiveData = Transformations.switchMap(mMaozyInitMaozyPaystackMaozySdkMaozyLiveData) { query ->
        ApiUserReposity.initMaozyPaystackMaozySdk(this, query)
    }

    /** 获取paystack卡列表监听 */
    val onMaozyFetchMaozyPaystackMaozyCardMaozyListMaozyLiveData =
        Transformations.switchMap(mMaozyFetchMaozyPaystackMaozyCardMaozyListMaozyLiveData) { query ->
            ApiUserReposity.fetchMaozyPaystackMaozyCardMaozyList(this, query)
        }

    /** 获取虚拟账号信息 */
    fun fetchMaozyVirtualMaozyAccount(reqBase: ReqBase) {
        mMaozyFetchMaozyVirtualMaozyAccountMaozyLiveData.value = reqBase
    }

    /** 初始化paystack */
    fun initMaozyPaystackMaozySdk(reqPaystackOrderInitNgn: ReqPaystackOrderInitNgn) {
        mMaozyInitMaozyPaystackMaozySdkMaozyLiveData.value = reqPaystackOrderInitNgn
    }

    /** 获取paystack卡列表 */
    fun fetchMaozyPaystackMaozyCardMaozyList(reqBase: ReqBase) {
        mMaozyFetchMaozyPaystackMaozyCardMaozyListMaozyLiveData.value = reqBase
    }

    /** 初始化卡信息 */
    fun initMaozyCardMaozyInfo(revObjRepayDetail: RevObjRepayDetail) {
        mMaozyRepayMaozyAmount = revObjRepayDetail.repayAmount
        mMaozyCardMaozyNum = revObjRepayDetail.bankCardNo
        revObjRepayDetail.expiryYear?.let { expiryYear ->
            mMaozyEMaozyYear = expiryYear
        }
        revObjRepayDetail.expiryMonth?.let { expiryMonth ->
            mMaozyEMaozyMonth = expiryMonth
        }
        revObjRepayDetail.cvv?.let { cvv ->
            mMaozyEMaozyCvv = cvv
        }
        revObjRepayDetail.virtualBankName?.let { virtualBankName ->
            mMaozyVirtualMaozyBankMaozyName = virtualBankName
        }
        revObjRepayDetail.virtualBankAccount?.let { virtualBankAccount ->
            mMaozyVirtualMaozyBankMaozyAccount = virtualBankAccount
        }
    }
}